<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>正则扩展-命名捕获分组</title>
</head>

<body>

  <script>
    /* // 声明一个字符串
    let str = '<a href="http://www.atguigu.com">尚硅谷</a>';

    // 提取 url 与 [标签文本]
    const reg = /<a href="(.*)">(.*)<\/a>/;
    
    // 执行
    const result = reg.exec(str);

    console.log(result); */

    /* 
      Array(3)
      0: "<a href=\"http://www.atguigu.com\">尚硅谷</a>"
      1: "http://www.atguigu.com"
      2: "尚硅谷"
      groups: undefined
      index: 0
      input: "<a href=\"http://www.atguigu.com\">尚硅谷</a>"
      length: 3
    */ 

    // console.log(result[1]);
    // console.log(result[2]);

    let str = '<a href="http://www.atguigu.com">尚硅谷</a>';

    const reg = /<a href="(?<url>.*)">(?<txt>.*)<\/a>/;

    const result = reg.exec(str);

    console.log(result);
    /* 
      0: "<a href=\"http://www.atguigu.com\">尚硅谷</a>"
      1: "http://www.atguigu.com"
      2: "尚硅谷"
      groups: {url: 'http://www.atguigu.com', txt: '尚硅谷'}
      index: 0
      input: "<a href=\"http://www.atguigu.com\">尚硅谷</a>"
      length: 3
    */

  </script>
</body>

</html>